package Ventanas;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.Toolkit;

import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.JComboBox;

import Gestores.SistemaPizzaSugerida;

public class ventanaBorrarSugerida extends JFrame {

	private JPanel contentPane;
	private JComboBox comboBox;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ventanaBorrarSugerida frame = new ventanaBorrarSugerida();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @throws SQLException 
	 * @throws ClassNotFoundException 
	 */
	public ventanaBorrarSugerida() throws ClassNotFoundException, SQLException {
		setIconImage(Toolkit.getDefaultToolkit().getImage("src\\Fotos\\txoPizzeria.jpg"));
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnVolver = new JButton("Volver");
		btnVolver.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				ventanaConsultarVotosPizzas v;
				try {
					v = new ventanaConsultarVotosPizzas();
					v.setLocationRelativeTo(null);
					v.setVisible(true);
				} catch (ClassNotFoundException | SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			
			}
		});
		btnVolver.setBounds(26, 222, 89, 23);
		contentPane.add(btnVolver);
		
		comboBox = new JComboBox();
		comboBox.setBounds(218, 61, 158, 20);
		contentPane.add(comboBox);
		
		SistemaPizzaSugerida sp=new SistemaPizzaSugerida();
		ArrayList <String> sugeridas=sp.usersList();
		int i=0;
		if(!sugeridas.isEmpty()){
			
			while(i<sugeridas.size()){
				comboBox.addItem(sugeridas.get(i));
				i++;
			}
		}
		
		JLabel lblElegirPizzaSugerida = new JLabel("Elegir pizza sugerida a borrar:");
		lblElegirPizzaSugerida.setBounds(24, 64, 184, 14);
		contentPane.add(lblElegirPizzaSugerida);
		
		JButton btnEliminarPizza = new JButton("Eliminar Pizza");
		btnEliminarPizza.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					SistemaPizzaSugerida.conectar();
					SistemaPizzaSugerida.borrarPizza(comboBox.getSelectedItem().toString());
					SistemaPizzaSugerida.desconectar();
					JOptionPane.showMessageDialog(null,"La pizza sugerida "+comboBox.getSelectedItem().toString()+" ha sido borrada");
					setVisible(false);
					ventanaConsultarVotosPizzas v;

					v = new ventanaConsultarVotosPizzas();
					v.setLocationRelativeTo(null);
					v.setVisible(true);
					
				} catch (ClassNotFoundException | SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
			}
		});
		btnEliminarPizza.setBounds(246, 152, 130, 32);
		contentPane.add(btnEliminarPizza);
		
		JLabel lblNewLabel = new JLabel("New label");
		lblNewLabel.setIcon(new ImageIcon("src\\Fotos\\fondo-textured-blanco-y-azul-abstracto-5013168.jpg"));
		lblNewLabel.setBounds(0, 0, 444, 271);
		contentPane.add(lblNewLabel);
	}
}
